/**********************************************
*  Classes:   SkyBox
*  Desc:      A box that surrounds the scene
*  Author:    Vaios Kalpias-Ilias (C) 2008-2009
***********************************************/

#ifndef SKYBOX_H
#define SKYBOX_H

#include "SmartPointer.h"
class TextureProperty;
SmartPointer(TextureProperty);

class SkyBox
{
public:

	enum BoxPlane
	{
		PLANE_FAR = 0,
		PLANE_NEAR,
		PLANE_RIGHT,
		PLANE_LEFT,
		PLANE_TOP,
		PLANE_BOTTOM
	};

	SkyBox() : m_fSize(1.0f),
		       m_bMoveWithCamera(true),
			   m_bTextured(false),
			   m_bMultipleTextures(false)
	{}

	~SkyBox()
	{
		for (int i=0; i<6; ++i)
		{
			m_pTextures[i] = TexturePropertyPtr();
		}
	}

	// set the textures of the box
	void SetTextures(TexturePropertyPtr texture)
	{
		if (!texture) return;
		
		for (int i=0; i<6; ++i)
		{
			m_pTextures[i] = texture;
		}

		m_bTextured = true;
	}

	void SetTextures(TexturePropertyPtr nearP,
					 TexturePropertyPtr farP,
					 TexturePropertyPtr leftP,
					 TexturePropertyPtr rightP,
					 TexturePropertyPtr topP,
					 TexturePropertyPtr bottomP)
	{
		if (nearP && farP && leftP && rightP
			&& topP && bottomP)
		{
			m_pTextures[PLANE_NEAR] = nearP;
			m_pTextures[PLANE_FAR] = farP;
			m_pTextures[PLANE_LEFT] = leftP;
			m_pTextures[PLANE_RIGHT] = rightP;
			m_pTextures[PLANE_TOP] = topP;
			m_pTextures[PLANE_BOTTOM] = bottomP;

			m_bTextured = true;
			m_bMultipleTextures = true;
		}
	}
	
	void SetMoveWithCamera (bool value)
	{
		m_bMoveWithCamera = value;
	}

	void SetSize(float size)
	{
		m_fSize = size;
	}

	const bool GetMoveWithCamera () const
	{
		return m_bMoveWithCamera;
	}

	const float GetSize() const
	{
		return m_fSize;
	}

	const bool IsTextured() const
	{
		return m_bTextured;
	}
	
	const bool HasMultipleTextures() const
	{
		return m_bMultipleTextures;
	}


	TexturePropertyPtr GetTexture(unsigned int index)
	{
		if (index < 7)
			return m_pTextures[index];

		return TexturePropertyPtr();
	}

private:

	

	// the size of the box
	float m_fSize;

	// specifies if the box move like the camera
	bool m_bMoveWithCamera;

	// specifies if the box has a texture
	bool m_bTextured;

	// specifies if the box has more than one texture
	bool m_bMultipleTextures;


	// plane textures
	TexturePropertyPtr m_pTextures[6];

};

SmartPointer(SkyBox);

#endif